package cn.crm.Service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.crm.Service.ICustomerService;
import cn.crm.common.ServerResponse;
import cn.crm.entity.Customer;
import cn.crm.mapper.CustomerMapper;

@Service
public class CustomerServiceImpl implements ICustomerService{

	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public ServerResponse pageList(Integer page, Integer limit, Customer customer) {
		// TODO Auto-generated method stub
		PageHelper.startPage(page, limit);
		List<Customer> list = customerMapper.pageList(customer);
		PageInfo pageInfo = new PageInfo<>(list);
		int count = (int) pageInfo.getTotal();
		return ServerResponse.createSuccess("查找成功", count, list);
	}

	@Override
	public ServerResponse insert(Customer customer) {
		int count = customerMapper.insert(customer);
		if (count == 1) {
			return ServerResponse.createSuccess("添加成功");
		}else {
			return ServerResponse.createError("添加失败");
		}
	}

	@Override
	public ServerResponse selectIds() {
		// TODO Auto-generated method stub
		List list = customerMapper.pageList(new Customer());
		return ServerResponse.createSuccess("查找成功", list);
	}
}
